package com.chen.utils;

import cn.hutool.core.util.RandomUtil;
import org.springframework.stereotype.Component;

/**
 * @author cws
 * @since
 */
@Component
public class CommonUtils {

    /**
     * 16位优惠码生成：时间戳后8位+4位随机数+用户id后4位
     */
    private String generateCouponCode(Long memberId){
        StringBuilder sb = new StringBuilder();
        Long currentTimeMillis = System.currentTimeMillis();
        String timeMillisStr = currentTimeMillis.toString();
        sb.append(timeMillisStr.substring(timeMillisStr.length()-8));
        sb.append(RandomUtil.randomNumbers(4));
        String memberIdStr = memberId.toString();
        if (memberIdStr.length()<=4){
            sb.append(String.format("%4d",memberId));
        }else {
            sb.append(memberIdStr.substring(memberIdStr.length()-4));
        }
        return sb.toString();
    }


}

